/**
 * 字段库相关类型定义
 */

import type {BaseEntity, PageResponse} from '../common/base'

/**
 * 字段类型枚举
 */
export enum ColumnType {
  VARCHAR = 'VARCHAR',
  CHAR = 'CHAR',
  TEXT = 'TEXT',
  INT = 'INT',
  INTEGER = 'INTEGER',
  BIGINT = 'BIGINT',
  DECIMAL = 'DECIMAL',
  NUMERIC = 'NUMERIC',
  DATE = 'DATE',
  DATETIME = 'DATETIME',
  TIMESTAMP = 'TIMESTAMP',
  BOOLEAN = 'BOOLEAN'
}

/**
 * 字段库实体
 */
export interface FieldLibrary extends BaseEntity {
  productId: number
  fieldNameCn: string
  fieldNameEn: string
  fieldType: ColumnType
  fieldLength?: number
  fieldScale?: number
  isRequired: boolean
  isPrimaryKey: boolean
  isUnique: boolean
  defaultValue?: string
  fieldComment?: string
  isEnabled: boolean
  usageCount: number
}

/**
 * 字段库搜索请求
 */
export interface FieldLibrarySearchRequest {
  productId: number
  keyword?: string
  fieldType?: ColumnType
  isRequired?: boolean
  isPrimaryKey?: boolean
  isUnique?: boolean
  isEnabled?: boolean
  page?: number
  size?: number
}

/**
 * 创建字段库请求
 */
export interface CreateFieldLibraryRequest {
  productId: number
  fieldNameCn: string
  fieldNameEn?: string
  fieldType: ColumnType
  fieldLength?: number
  fieldScale?: number
  isRequired?: boolean
  isPrimaryKey?: boolean
  isUnique?: boolean
  defaultValue?: string
  fieldComment?: string
  isEnabled?: boolean
}

/**
 * 更新字段库请求
 */
export interface UpdateFieldLibraryRequest {
  fieldNameCn?: string
  fieldNameEn?: string
  fieldType?: ColumnType
  fieldLength?: number
  fieldScale?: number
  isRequired?: boolean
  isPrimaryKey?: boolean
  isUnique?: boolean
  defaultValue?: string
  fieldComment?: string
  isEnabled?: boolean
}

/**
 * 字段库分页响应
 */
export type FieldLibraryPageResponse = PageResponse<FieldLibrary>

/**
 * 字段组
 */
export interface FieldGroup {
  name: string
  fields: FieldLibrary[]
}

/**
 * 字段库统计
 */
export interface FieldLibraryStats {
  totalFields: number
  enabledFields: number
  disabledFields: number
  popularFields: FieldLibrary[]
  fieldTypes: Array<{
    type: ColumnType
    count: number
  }>
}

/**
 * 字段翻译结果
 */
export interface FieldTranslation {
  originalName: string
  translatedName: string
  confidence?: number
}